package ui;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.parkcar.R;

public class AlertDialog extends Dialog {
	
	private EditText editText0;
	
	private TextView tvTitle;
	
	private TextView tvMsg;
	
	private Button btnNegative;
	
	private Button btnPositive;
	
	private Context context;
	private LinearLayout stork_ll;

	public AlertDialog(Context context) {
		super(context);
		this.context = context;
		
		initView();
	}
	
	private void initView(){
		View view = LayoutInflater.from(context).inflate(R.layout.dialog_base, null);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(view);
		editText0 = (EditText) view.findViewById(R.id.edit_text0);
		tvTitle = (TextView) view.findViewById(R.id.tv_title);
		tvMsg = (TextView) view.findViewById(R.id.alt_msg);
		btnNegative = (Button) view.findViewById(R.id.btn_negative);
		btnPositive = (Button) view.findViewById(R.id.btn_positive);
		stork_ll = (LinearLayout) view.findViewById(R.id.stork_ll);
		btnNegative.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				dismiss();
			}
		});
	}
	
	public AlertDialog setDisplayMsg(String title, String message, boolean showEdit0){
		if (TextUtils.isEmpty(title)) {
			tvTitle.setVisibility(View.GONE);
		}
		else {
			tvTitle.setText(title == null ? "" : title);
		}
		
		if (TextUtils.isEmpty(message)) {
			tvMsg.setVisibility(View.GONE);
		}
		else {
			tvMsg.setText(message == null ? "" : message);
		}
		
		if(showEdit0){
			editText0.setVisibility(View.VISIBLE);
			stork_ll.setVisibility(View.VISIBLE);
		}
		else{
			editText0.setVisibility(View.GONE);
			stork_ll.setVisibility(View.GONE);
		}
		
		return this;
	}
	
	public void setPositive(String str, View.OnClickListener listener){
		btnPositive.setText(str);
		btnPositive.setOnClickListener(listener);
	}
	
	public void setNegative(String str, View.OnClickListener listener){
		btnNegative.setText(str);
		btnNegative.setOnClickListener(listener);
	}

	public EditText getEditText0() {
		return editText0;
	}
	@Override
	public void setTitle(CharSequence title) {
		tvTitle.setText(title);
	}
	public void setMessage(String message){
		tvMsg.setText(message);
	}

	public void setStork_ll(boolean b){
		if (b){
			stork_ll.setVisibility(View.VISIBLE);
		}else {
			stork_ll.setVisibility(View.GONE);
		}
	}
}
